package com.ruoyi.shop.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.shop.domain.Goods_Category;
import com.ruoyi.shop.service.IGoods_CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/backstage/goodsCategory")
public class Goods_CategoryController extends BaseController {
    @Autowired
    private IGoods_CategoryService goodsCategoryService;

    @PreAuthorize("@ss.hasPermi('backstage:goodsinfo:query')")
    @GetMapping("/category/{gid}")
    public AjaxResult getCategory(@PathVariable("gid") Integer gid) {
        List<Goods_Category> list = goodsCategoryService.getGoods_Category(gid);
        return AjaxResult.success(list);
    }

    @DeleteMapping("/delCategory/{id}")
    public AjaxResult delGoodsCategory(@PathVariable("id") Integer id) {
        Integer i = goodsCategoryService.deleteGoods_Category(id);
        return AjaxResult.success(i);
    }

    @PostMapping
    public AjaxResult insertGoodsCategory(@RequestBody Goods_Category goodsCategory) {
        return toAjax(goodsCategoryService.insertGoods_Category(goodsCategory.getGoodsId(), goodsCategory.getCategoryId()));
    }
}
